<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>

<script>
    // const p = new Promise((resolve, reject) => {
    //     setTimeout(() => {

    //     }, 1000);
    // });
    // console.log(p);

    /**
     * promise.race调用
     */
    const getData = () => {
        return new Promise((resolve) => {
            setTimeout(() => {
                console.log("发送网络请求获取数据");
                resolve("success get Data");
            }, 2500);
        })
    }

    const timer = () => {
        return new Promise((_, reject) => {
            setTimeout(() => {
                reject("timeout");
            }, 2000);
        })
    }

    const p = Promise.race([getData(), timer()])
        .then((res) => {
            console.log("获取数据：", res);
        })
        .catch((err) => {
            console.log("超时：", err);
        })

    console.log(p);



</script>

</html>